package com.ruoyi.web.controller.ora;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.dict.SysNormalDisable;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ora.domain.MemberLevel;
import com.ruoyi.ora.service.IMemberLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会员等级配置Controller
 * 
 * @author liuwp
 * @date 2024-11-25
 */
@RestController
@RequestMapping("/ora/member_level")
public class MemberLevelController extends BaseController
{
    @Autowired
    private IMemberLevelService memberLevelService;

    /**
     * 查询会员等级配置列表
     */
    @PreAuthorize("@ss.hasPermi('ora:member_level:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberLevel memberLevel)
    {
        startPage();
        List<MemberLevel> list = memberLevelService.selectMemberLevelList(memberLevel);
        return getDataTable(list);
    }

    /**
     * 导出会员等级配置列表
     */
    @PreAuthorize("@ss.hasPermi('ora:member_level:export')")
    @Log(title = "会员等级配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberLevel memberLevel)
    {
        List<MemberLevel> list = memberLevelService.selectMemberLevelList(memberLevel);
        ExcelUtil<MemberLevel> util = new ExcelUtil<MemberLevel>(MemberLevel.class);
        util.exportExcel(response, list, "会员等级配置数据");
    }

    /**
     * 获取会员等级配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('ora:member_level:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(memberLevelService.selectMemberLevelById(id));
    }

    /**
     * 新增会员等级配置
     */
    @PreAuthorize("@ss.hasPermi('ora:member_level:add')")
    @Log(title = "会员等级配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberLevel memberLevel)
    {
        return toAjax(memberLevelService.insertMemberLevel(memberLevel));
    }

    /**
     * 修改会员等级配置
     */
    @PreAuthorize("@ss.hasPermi('ora:member_level:edit')")
    @Log(title = "会员等级配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberLevel memberLevel)
    {
        return toAjax(memberLevelService.updateMemberLevel(memberLevel));
    }

    /**
     * 删除会员等级配置
     */
    @PreAuthorize("@ss.hasPermi('ora:member_level:remove')")
    @Log(title = "会员等级配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(memberLevelService.deleteMemberLevelByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('ora:member_level:list')")
    @GetMapping("/list/all")
    public AjaxResult listAll(MemberLevel memberLevel)
    {
//        TODO 根据用户位置获取充值信息
        if (StringUtils.isNotEmpty(memberLevel.getPosition())){
//            memberLevel.setPosition();
//            设备坐标参数
        }
        memberLevel.setStatus(SysNormalDisable.NORMAL.getValue());
        List<MemberLevel> list = memberLevelService.selectMemberLevelList(memberLevel);
        return AjaxResult.success(list);
    }
}
